<template>
  <view class="vehicle-verify-page page-content">
    <z-paging ref="paging" v-model="currentList" @query="queryList" :auto="false" :refresher-enabled="true"
      :loading-more-enabled="true" empty-view-text="暂无数据">
      <template #top>
        <up-navbar title="停车泊位列表" :autoBack="false" :fixed="true" bgColor="transparent" :border="false" placeholder
          @leftClick="handleBackClick">
          <template #right>
            <view @click="handleAdd">新增设备</view>
          </template>
        </up-navbar>

        <up-sticky class="padding-20" bgColor="transparent">
          <view class="header-bar">
            <view class="header-bar-location" @click="showTimePicker = true">
              <text class="title">泊位身份</text>
              <up-icon name="arrow-down"></up-icon>
            </view>
            <up-picker :show="showTimePicker" :columns="columns" :closeOnClickOverlay="true"
              @confirm="showTimePicker = false" @cancel="showTimePicker = false"
              @close="showTimePicker = false"></up-picker>
          </view>

          <up-search :clearabled="true" :showAction="false" placeholder="请输入停车场名称"></up-search>
        </up-sticky>
      </template>

      <view class="vehicle-verify-list">
        <view class="list-item-card" v-for="(item, index) in currentList" :key="index">
          <view class="card-header">
            <view class="title">
              泊位号：<text class="number">38005208</text>
            </view>
          </view>
          <view class="card-content-box">
            <view class="content">
              <view class="item">
                <text class="label">
                  状态：
                </text>
                <view class="value">
                  <view class="item-tag">
                    <up-tag text="临停泊位" type="success"></up-tag>
                  </view>
                  <view class="item-tag">
                    <up-tag text="有车" type="success"></up-tag>
                  </view>
                  <view class="item-tag">
                    <up-tag text="在线" type="success"></up-tag>
                  </view>
                </view>
              </view>
              <view class="item">
                <text class="label">
                  停车场：
                </text>
                <text class="value">
                  杏坛镇新齐宁路
                </text>
              </view>
              <view class="item">
                <text class="label">
                  详细地址：
                </text>
                <text class="value">
                  顺德区杏坛镇
                </text>
              </view>
              <view class="item">
                <text class="label">
                  所属运营商：
                </text>
                <text class="value">
                  大良镇
                </text>
              </view>
              <view class="item">
                <text class="label">
                  免布线视频桩：
                </text>
                <text class="value">
                  DTW202433108555
                </text>
              </view>
              <view class="item">
                <text class="label">
                  智能高位视频：
                </text>
                <text class="value">
                  12020006c839
                </text>
              </view>
            </view>
            <view class="card-footer">
              <view class="checkbox-box">
              </view>
              <view class="operate">
                <up-button type="primary" text="编辑设备" class="custom-style" @click="handleEdit(item)"></up-button>
                <up-button type="error" text="删除设备" class="custom-style" @click="handleDel(item)"></up-button>
              </view>
            </view>
          </view>
        </view>
      </view>
    </z-paging>

    <ParkingBerthModal v-model:show="show" :type="type" :row-data="editingData" />
    <up-modal :show="showDelModal" contentTextAlign="center" showCancelButton closeOnClickOverlay title="提示"
      content='是否确认删除？' @cancel="closeDelModal" @confirm="closeDelModal" @close="closeDelModal"></up-modal>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { getRealNameVerifyList } from '@/api';
import ParkingBerthModal from './components/ParkingBerthModal.vue';

const type = ref('add');
const { bool: show, setTrue: openModal } = useBoolean();
const { bool: showDelModal, setTrue: openDelModal, setFalse: closeDelModal } = useBoolean();
const editingData = ref<any>(null);

const currentTab = ref(0);
const showTimePicker = ref(false);
const columns = reactive([
  ['临停泊位', '产权泊位', '月租泊位']
]);
// z-paging 组件引用
const paging = ref(null)

// 当前显示的列表数据
const currentList = ref([])

// 处理返回点击事件
const handleBackClick = () => {
  uni.redirectTo({
    url: '/pages/home/index'
  })
}

const handleDel = (item: any) => {
  openDelModal()
}

const handleAdd = () => {
  type.value = 'add'
  openModal();
}

const handleEdit = (item: any) => {
  type.value = 'edit'
  editingData.value = {
    parkingId: "1",
    berthNo: "38005208, 38005207",
  }
  openModal();
}

// 获取车辆列表数据
const queryList = async (pageNo, pageSize) => {
  console.log(pageNo, pageSize, currentTab.value)

  const params = {
    pageNum: pageNo,
    pageSize
  }

  await fetchList(params)
};

const fetchList = async (params) => {
  try {
    const result: any = await getRealNameVerifyList({ ...params, status: currentTab.value === 0 ? undefined : currentTab.value })
    const data = result.data
    paging.value.complete(data.records || [])
  } catch (error) {
    paging.value.complete(false)
  }
}


// 搜索按钮点击事件
const handleSearch = () => {
};

// 页面挂载时获取数据
onMounted(() => {
  fetchList({
    pageNum: 1,
    pageSize: 10,
  })
});
</script>

<style scoped lang="scss">
.vehicle-verify-list {
  padding: 20px;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0rpx 20rpx 30rpx;

  .time-picker {
    width: 480rpx;
    display: flex;
    align-items: center;

    .title {
      font-size: 28rpx;
      font-weight: bold;
      color: #333;
      margin-right: 10rpx;
    }
  }

  &-location {
    display: flex;
    align-items: center;

    .location-icon {
      width: 40rpx;
      height: 40rpx;
      margin-right: 10rpx;
    }

    .title {
      font-size: 28rpx;
      font-weight: bold;
      color: #333;
      margin-right: 10rpx;
    }

    .arrow-icon {
      width: 30rpx;
      height: 30rpx;
    }
  }

  .waiting-count {
    font-weight: 500;
    font-size: 24rpx;
    color: #333333;
    display: flex;
    align-items: center;

    text {
      font-weight: bold;
      font-size: 36rpx;
      color: #fe6000;
      margin-left: 10rpx;
    }
  }
}

/* 列表统计 */
.list-statistics {
  display: flex;
  flex-wrap: wrap;
  padding: 20rpx 0;
}

.list-statistics .item {
  flex: 1 1 20%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.list-statistics .label {
  font-size: 14px;
  color: #666;
}

.list-statistics .value {
  font-size: 18px;
  font-weight: bold;
  color: #e9710f;
}

.search-bar {
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}
</style>